#include "Bridge.h"


Bridge::Bridge(int X, int Y)
{
	m_X = X;
	m_Y = Y;
	m_IsEffect = false;

	for (int i = 0; i < 4; i++)
	{
		Explode *temp = new Explode();
		temp->Init(IDImage::IMG_MachineExplode);
		m_FrameExplode.push_back(temp);

		Sprite *sprite = Source::getInstance()->getSprite(IDImage::IMG_Bridge);
		sprite->setIndex(i);
		m_FrameSprite.push_back(sprite);
	}

	m_TimeAnimation = 0.5f;
	m_Gametime = new GameTime();
	m_Temp = 0;
}
void Bridge::Check(int X, int Y)
{
	if (m_Position.x == X)
	{
		m_IsEffect = true;
	}
}
void Bridge::Update()
{
	m_Vpx = 0;
	m_Vpy = VIEW_PORT_Y;
	m_Gametime->setTime();

	if (m_Gametime->getElapsedTimePerSecond() >= m_TimeAnimation * 1.75)
	{
		if (m_IsEffect)
		{
			if (m_Gametime->getElapsedTimePerSecond() >= m_TimeAnimation * 1.75)
			{
				m_Gametime->Update();

				m_Sprite = m_FrameSprite[m_Temp];
				for (int i = 0; i < 4; i++)
				{
					m_Explode = m_FrameExplode[i];
					m_Explode->Next();
				}

				if (m_Explode->NoneEffect())
				{
					for (int i = 0; i < 4; i++)
					{
						m_FrameExplode[i]->Reset();
					}
					
					if (m_Temp != 4)
					{
						m_Temp++;
					}
				}
			}
			return;
		}
	}
}

void Bridge::Draw(LPD3DXSPRITE SpriteHandler)
{
	for (int i = 0; i < m_FrameSprite.size(); i++)
	{
		m_Sprite = m_FrameSprite[i];
		m_Position.x = m_X + i*32;
		m_Position.y = m_Y;

		CObject::Draw(SpriteHandler);
	}
}

Bridge::~Bridge()
{
}
